<template>
	<view class="enterpriseType">
		<view class="title">用户类型</view>

		<view class="type">
			<text class="text" v-for="item in purchaserList" :key="item.orderNum" @click="selectType(item)"
				:class="id===item.id?'active':''">
				{{item.name}}
			</text>
		</view>

		<button class="register_button" @click="submitForm">下一步</button>

	</view>
</template>

<script>
	import jwtDecode from 'jwt-decode'
	import {
		getPurchaserInfo,
		getPurchaser,
		setPurchaser
	} from '@/api/reg/index'

	export default {
		data() {
			return {
				id: '',
				mold: '',
				purchaserList: [],
			}
		},
		onShow() {
			let a = JSON.parse(jwtDecode(uni.getStorageSync('token')).userContext.replace('\\', ''))
			getPurchaserInfo(a.purchaserId).then(re => {
				if (re.code === 200) this.mold = re.data.mold
			}).finally(() => {
				getPurchaser().then(res => {
					if (res.code === 200) {
						this.purchaserList = res.data
						this.purchaserList.forEach(i => {
							if (i.id === this.mold) {
								this.id = i.id
							}
						})
					}
				})
			})
		},
		methods: {
			selectType(e) {
				this.id = e.id
			},
			submitForm() {
				if (!this.id) return
				setPurchaser({
					mold: this.id
				}).then(res => {
					if (res.code === 200) {
						uni.navigateTo({
							url: `/pages_user/reg/qualificationList`
						})
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.enterpriseType {
		padding-top: 58rpx;
	}

	.title {
		font-size: 33rpx;
		line-height: 1;
		font-weight: 500;
		margin-left: 40rpx;
		margin-bottom: 88.89rpx;
	}

	.type {
		padding-left: 41.67rpx;

		display: flex;
		flex-flow: row wrap;

		.text {
			background: #f3f3f3;
			border-radius: 50rpx;
			color: #7e7e7e;
			font-size: 29rpx;
			padding: 9.72rpx 27.08rpx 10.42rpx;
			margin-right: 55.56rpx;
			margin-bottom: 55.56rpx;
			font-weight: 400;
		}

		.active {
			background: #f3f7ff;
			border: 1px solid #2871fc;
			color: #2871fc;
		}
	}

	.register_button {
		width: 667rpx;
		height: 72rpx;
		background: #2871fc;
		border-radius: 36rpx;
		color: #fff;
		font-size: 29rpx;
		position: fixed;
		left: 50%;
		bottom: 104rpx;
		transform: translateX(-50%);
		z-index: 10;
	}
</style>